package com.wlcorp.forcazamis.dao.baseinfo.impl;

import java.util.List;

import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

import com.ibatis.dao.client.DaoException;
import com.wlcorp.forcazamis.dao.baseinfo.IDepotDAO;
import com.wlcorp.forcazamis.domain.baseinfo.Depot;

public class DepotDAOImpl extends HibernateDaoSupport implements IDepotDAO {

	@SuppressWarnings("unchecked")
	public List getDepotList(Depot depot) throws DaoException {
		StringBuffer hql=new StringBuffer("from Depot d where 1=1 and d.deleteFlag=false");
		if(null!=depot&&null!=depot.getDepotName()&&!depot.getDepotName().equals("")){
			hql.append(" and d.depotName='").append(depot.getDepotName()).append("'");
		}
		return getHibernateTemplate().find(hql.toString());
	}

	public Depot getDepotById(Long depotId) throws DaoException {
		return (Depot)getHibernateTemplate().get(Depot.class,depotId);
	}

	public void deleteDepot(Depot depot) throws DaoException {
		depot.setDeleteFlag(true);
		getHibernateTemplate().update(depot);
	}

	public void saveDepot(Depot depot) throws DaoException {
		getHibernateTemplate().saveOrUpdate(depot);
	}
}
